package com.henu.ocr.api.controller;

import com.henu.ocr.annotation.IgnoreToken;
import com.henu.ocr.annotation.Timed;
import com.henu.ocr.api.model.DataDistributionRequestModel;
import com.henu.ocr.api.model.DataDistributionResponseModel;
import com.henu.ocr.api.service.serviceImpl.DataDistributionServiceImpl;
import com.henu.ocr.mapper.CompanyMapper;
import com.henu.ocr.service.UserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@SuppressWarnings("all")
@Tag(name = "数据分发接口")
@Slf4j
@RequestMapping("data/api")
public class DataDistributionController {
    @Resource
    DataDistributionServiceImpl dataDistributionService;
    @Resource
    private CompanyMapper companyMapper;
    @Resource
    private UserService userService;

    @IgnoreToken
    @Timed
    @PostMapping("dataDistribution")
    public DataDistributionResponseModel dataDistribution(@RequestBody DataDistributionRequestModel model) {
        String type = model.getMdType();
        switch (type) {
            case "org001":
                return dataDistributionService.dealWithOrgWithDetails(model);
            case "dept001":
                return dataDistributionService.dealWithDept(model);
            case "psn001":
                return dataDistributionService.dealWithPsn(model);
            case "trader001":
                return dataDistributionService.dealWithTrader(model);
            case "pro001":
                return dataDistributionService.dealWithPro(model);
            default:
                return new DataDistributionResponseModel("数据分发类型错误,mdType wrong", model.get("mdm_code"), model.getMdType(), null);
        }
    }
}
